package com.fjnldx.mes.service.scheduling;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.fjnldx.mes.domain.domainRes.Result;
import com.fjnldx.mes.domain.pojo.SchedulingPersonnel;
import com.fjnldx.mes.mapper.common.MesContainerMapper;
import com.fjnldx.mes.mapper.scheduling.DingPersonTableMapper;
import com.fjnldx.mes.mapper.scheduling.SchedulingPersonnelMapper;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

@Service
public class TimingScheduling {
    @Resource
    SchedulingPersonnelMapper schedulingPersonnelMapper;
    @Resource
    DingPersonTableMapper dingPersonTableMapper;
    @Resource
    MesContainerMapper mesContainerMapper;
    /**
     * 人员表添加数据
     * 每日12点执行
     */
    @Scheduled(cron = "00 00 12 * * ?")
    @Async
    public Result insertIntoSchedulingPersonnel() {
        QueryWrapper<SchedulingPersonnel> schedulingPWrapper = new QueryWrapper<>();
        List<SchedulingPersonnel> schedulingResults = schedulingPersonnelMapper.selectList(schedulingPWrapper);
        ArrayList<String> ghList = new ArrayList<>();
        for (SchedulingPersonnel item : schedulingResults) {
            ghList.add(item.getGh());
        }
        mesContainerMapper.insertIntoSchedulingPersonnel(ghList);

        return Result.success("同步成功");
    }
}
